<!--  -->
<template>
  <div class="orderlist">
    <van-nav-bar
      @click-left="onClickLeft"
      title="订单管理"
      :left-arrow="true"
    />
    <van-tabs
      v-model="active"
      :border="false"
      @click="onClick"
      color="#FF4732"
      title-active-color="#FF4732"
    >
      <van-tab title="待发货" name="S">
        <div class="cell_main" v-for="(v, k) in data.list" :key="k">
          <img class="limg" :src="v.thumb" />
          <div class="main_r">
            <div class="name">
              <div class="column">{{ v.name }}</div>
              <p>兑换时间 {{ timer(v.addtime) }}</p>
            </div>
            <div class="money">
              <div class="jifen">
                {{ v.money }}
                <img src="@/assets/img/order/jianguo.png" />
              </div>
              <p class="number">x{{ v.num }}</p>
              <p class="state" v-if="v.status != 'D'">{{ v.status_name }}</p>
              <p
                class="state"
                v-if="v.status === 'D'"
                @click="goToDetail(v.id, v.courier_id)"
              >
                查看物流
              </p>
            </div>
          </div>
        </div>
      </van-tab>
      <van-tab title="已发货" name="D">
        <div class="cell_main" v-for="(v, k) in data.list" :key="k">
          <img class="limg" :src="v.thumb" />
          <div class="main_r">
            <div class="name">
              <div class="column">{{ v.name }}</div>
              <p>兑换时间 {{ timer(v.addtime) }}</p>
            </div>
            <div class="money">
              <div class="jifen">
                {{ v.money }}
                <img src="@/assets/img/order/jianguo.png" />
              </div>
              <p class="number">x{{ v.num }}</p>
              <p class="state" v-if="v.status != 'D'">{{ v.status_name }}</p>
              <p
                class="state"
                v-if="v.status === 'D'"
                @click="goToDetail(v.id, v.courier_id)"
              >
                查看物流
              </p>
            </div>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import Fetch from "../../utils/fetch";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    name: "orderlist",
  },
  data() {
    //这里存放数据
    return {
      active: "S",
      data: {
        config: {
          status: {},
        },
      },
      status: "S",
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    onClick() {
      Fetch("/goods/order/search", { status: this.active }).then((res) => {
        this.data = res.data;
      });
    },
    init() {
      Fetch("/goods/order/search", { status: this.status }).then((res) => {
        this.data = res.data;
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    goToDetail(id, dh) {
      if (dh) {
        this.$router.push({
          path: "/logistics",
          query: {
            id: id,
            dh: dh,
          },
        });
        // this.$router.push({
        //   path: `/order/${id}/${dh}`,
        // });
      } else {
        this.$notify({
          message: "物流单号有误，请联系客服",
          color: "#FF3232",
          background: "#FFEAEA",
        });
      }
    },
    timer(t) {
      var time = new Date(t * 1000);
      return (
        time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate()
      );
    },
    logistics() {
      this.$router.push({
        path: "/logistics",
        // query: {
        // },
      });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.init();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped lang="less">
/* //@import url(); 引入公共css类 */
.orderlist {
  width: 100%;
  height: 100%;
  background: #f2f2f2;
  .cell_main {
    background: #ffffff;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 18px;
    margin-top: 10px;
    .limg {
      width: 87px;
      height: 87px;
      margin-right: 10px;
      border: 1px solid #dfdfdf;
      border-radius: 10px;
    }
    .main_r {
      width: calc(100% - 97px);
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: flex-start;
      padding: 6px 0 13px 0;

      .name {
        width: 75%;
        .column {
          height: 52px;
          font-size: 15px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          color: #20253a;
          line-height: 21px;
          letter-spacing: 1px;
        }
        p {
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          color: #999999;
          letter-spacing: 1px;
        }
      }
      .money {
        width: 25%;
        .jifen {
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Medium;
          font-weight: 500;
          color: #ff8f01;
          line-height: 17px;
          letter-spacing: 1px;
          text-align: right;
          img {
            width: 12px;
            height: 17px;
            vertical-align: middle;
          }
        }
        .number {
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Medium;
          font-weight: 500;
          text-align: right;
          color: #999999;
          line-height: 17px;
          letter-spacing: 1px;
          margin-bottom: 17px;
        }
        .state {
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: right;
          color: #666666;
          line-height: 17px;
          letter-spacing: 1px;
        }
      }
    }
  }
  /deep/ .van-nav-bar {
    box-shadow: none;
  }
  /deep/ .van-hairline--bottom::after {
    border-bottom-width: 0;
  }
  /deep/ .van-tabs--line .van-tabs__wrap {
    background: #ffffff;
  }
  /deep/ .van-tabs__nav--line {
    width: 55%;
    margin: 0 auto;
  }
}
</style>